﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Chat.aspx.cs" Inherits="Mall.Chat" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>聊天窗口</title>
    <style type="text/css">
        #ChatForm {
            width: 500px;
            margin: auto;
            border: 1px solid black;
            text-align: center;
            font-size: 20px;
        }
    </style>
    <script src="Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
</head>
<body style="text-align: center">
    <h1 style="color: Red; margin-top: 50px">欢迎<%=Session["Username"] != null ? Session["Username"].ToString() : ""%>，进入XX商城</h1><br />
    <div id="ChatForm">
    <div style="margin-top: 10px; ">
        <asp:Label ID="Label2" runat="server" Text="Label" style="color: Red; font-size: 24px;">客&nbsp;服&nbsp;沟&nbsp;通</asp:Label>
        <asp:Label ID="Label1" runat="server" Text="Label" style="color: Red; font-size: 24px;">客&nbsp;服&nbsp;咨&nbsp;询</asp:Label>
    </div>
    <div style="margin-top: 15px; margin-bottom: 10px; text-align: center; ">
        <div id="divContent" style="width: 400px; height: 300px; border: 1px solid black; margin: auto; 
            text-align: left; font-size: 16px; padding-top: 3px; padding-left: 3px; overflow-y: scroll;
            word-wrap:break-word; word-break:break-all; "></div>
            <span id="userTag" style="display: none"><%=Session["Username"] != null ? Session["Username"].ToString() : ""%></span>
        <div style="margin-top: 10px">
            <input id="sendMsg" type="text" style="width: 250px; height: 20px; font-size: 15px" />
            <input type="button" id="btnSend" style="margin-left: 10px; width: 60px; height: 24px; font-size: 18px" value="发 送" />
            <input type="button" id="btnReturn" style="width: 60px; height: 24px; font-size: 18px" value="返 回" />
        </div>
    </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            function send() {
                $.post("AsnyHandler.ashx", { content: getNowTime() + " " + $("#userTag").html() + "说：" + $("#sendMsg").val() });
                $("#sendMsg").val("");
            }
            function wait() {
                $.post("AsnyHandler.ashx", { content: "-1" },
            function (data, status) {
                var result = $("#divContent");
                if (result.html() != "") {
                    result.html(result.html() + "<br/>" + data);
                } else {
                    result.html(result.html() + data);
                }

                wait();
            }, "html"
         );
            }
            wait();
            $("#btnSend").click(function () { send(); });
            $("#sendMsg").keypress(function (event) {
                if (event.keyCode == 13) {
                    send();
                }
            });
            $("#btnReturn").click(function () {
                location.href = "Main.aspx";
            });
        });
        function getNowTime() {
            var now = new Date();
            var hour = now.getHours();
            var minute = now.getMinutes();
            var second = now.getSeconds();
            if (hour < 10) {
                hour = "0" + hour;
            }
            if (minute < 10) {
                minute = "0" + minute;
            }
            if (second < 10) {
                second = "0" + second;
            }
            return hour + ":" + minute + ":" + second;
        }
    </script>
</body>
</html>
